﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using STS.Schema.Interfaces;
using STS.Interfaces;
using STS.Schema.Enums;
using System.Runtime.Serialization;

namespace STS.Schema.Base
{
    public abstract class SqlObjectBase : ISqlObject
    {
        public virtual int? ParentObjectID
        {
            get;
            internal set;
        }

        public virtual int ObjectID
        {
            get;
            internal set;
        }

        public virtual string Name
        {
            get;
            internal set;
        }

        public ISchemaFactory Factory
        {
            get;
            internal set;
        }

        public IDictionary<string, ISqlObjectProperty> AllProperties
        {
            get;
            private set;
        }

        public IDatabase Database
        {
            get;
            protected set;
        }

        public SqlObjectBase()
            : this(null, null)
        {
        }

        public SqlObjectBase(ISchemaFactory schemaFactory, IDatabase database)
        {
            Factory = schemaFactory;
            AllProperties = new Dictionary<string, ISqlObjectProperty>();
            Database = database;
        }

        public ISqlObject Parent
        {
            get;
            protected set;
        }

        public virtual void Refresh()
        {
            AllProperties.Clear();
        }

        public override string ToString()
        {
            return string.Format("{0} (id = {1}, Type = {2})", this.Name, this.ObjectID, this.ObjectType);
        }

        public abstract ISqlObjectCollection GetChildren<TChild>() where TChild : class, ISqlObject, new();
        public abstract SqlObjectType ObjectType { get; }


       
    }
}
